#include <functional>
using namespace std;

void notify(int a);

void before() {
    int ret = 0;
    if (xxx) {
        ret = -1;
        notify(ret);
        return;
    }
    if (xxx) {
        ret = -2;
        notify(ret);
        return;
    }
    notify(ret);
}

void after1() {
    int ret = 0;

    class RAIIHelper {
    public:
        explicit RAIIHelper(int &r) : mRet(r) {}
        ~RAIIHelper() {
            notify(mRet);
        }
    private:
        int &mRet;
    } helper(ret);

    if (xxx) {
        ret = -1;
        return;
    }
    if (xxx) {
        ret = -2;
        return;
    }
}

class Defer {
public:
    explicit Defer(function<void()> f) : m_func(move(f)) {}

    ~Defer() { m_func(); }

private:
    function<void()> m_func;
};

void after2() {
    int ret = 0;
    Defer defer([&ret]() { notify(ret); });
    if (xxx) {
        ret = -1;
        return;
    }
    if (xxx) {
        ret = -2;
        return;
    }
}